package net.example.model.contract;

import com.oraycn.omcs.utils.BufferUtils;

import java.nio.charset.StandardCharsets;

import io.netty.buffer.ByteBuf;

public class GetAddFriend_GroupPageContract {
    public String UserID;
    public int PageIndex;
    public int PageSize;

    public GetAddFriend_GroupPageContract(String userID, int pageIndex, int pageSize) {
        this.UserID = userID;
        this.PageIndex = pageIndex;
        this.PageSize = pageSize;
    }

    /**
     * 消息转byte
     *
     * @return
     */
    public byte[] serialize() throws Exception {
        byte[] bUserID = UserID.getBytes(StandardCharsets.UTF_8);
        int contractLen = 4 + 4 + 4 + 4 + bUserID.length;
        ByteBuf body = BufferUtils.newBuffer();
        body.writeInt(contractLen);
        body.writeInt(PageIndex);
        body.writeInt(PageSize);
        body.writeInt(bUserID.length);
        body.writeBytes(bUserID);
        byte[] result = new byte[body.readableBytes()];
        System.arraycopy(body.array(), 0, result, 0, result.length);
        return result;
    }
}

